<template>
    <div class="changepwd">
        <div class="header">
            <span @click="GoBack()"><van-icon name="arrow-left" /></span>
            <p>修改密码</p>
            <span></span>
        </div>
        <section>
            <div class="loginInputs">
                <input type="password" class="pwd" placeholder="请输入大于六位密码" v-model="pwd">
                <div class="openSwitch">
                    <van-switch v-model="checked" @change="changeInput()" active-color="#07c160" inactive-color="white" size="26px"/>
                </div>
            </div>
            <button class="doLogin" @click="btnSub()">提交</button>
        </section>
    </div>
</template>
<script>
    import {ChangePwd} from "../../api/list/list";

    export default {
        name:'changePwd',
        data(){
            return{
                checked:false,
                pwd:'',
                uid:''
            }
        },
        created(){
            this.uid = this.$route.query.uid
        },
        methods:{
            changeInput(){
                let pwd = document.getElementsByClassName('pwd')[0]
                if(this.checked){
                    pwd.type = 'text'
                }else{
                    pwd.type = 'password'
                }
            },
            btnSub(){
                if(this.pwd != '' && this.pwd.length < 6){
                    this.$toast('请按照规则填写密码')
                }else{
                    const params = {
                        uid : this.uid,
                        password:this.pwd
                    }
                    ChangePwd(params).then((res)=>{
                        console.log(res)
                        if(res.data.code == 200){
                            this.$toast.success('修改成功');
                            history.go(-1)
                        }else{
                            this.$toast.fail('修改失败');
                        }
                    })
                }
            },
            GoBack(){
                history.go(-1)
            },
        }
    }
</script>
<style lang="less" scoped>
    .changepwd{
        width: 100%;
        height: 100%;
        display: flex;
        flex-direction: column;
        .header{
            width: 100%;
            height: 1rem;
            display: flex;
            border-bottom: 1px solid #efefef;
            span{
                width: 1rem;
                display: flex;
                align-items: center;
                justify-content: center;
                font-size: 0.4rem;
            }
            p{
                flex: 1;
                text-align: center;
                line-height: 1rem;
                font-size: 0.32rem;
            }
        }
        section {
            flex: 1;
            padding: 0.1rem 0.2rem;
            box-sizing: border-box;

            .loginInputs {
                border: 1px solid #efefef;
                display: flex;
                border-radius: 2px;
                margin: 0.2rem 0;

                input {
                    padding-left: 0.2rem;
                    box-sizing: border-box;
                    flex: 1;
                    height: 0.8rem;
                }

                .openSwitch {
                    width: 1.5rem;
                    display: flex;
                    align-items: center;
                    justify-content: center;
                }
            }
            .doLogin{
                background: #EB1625;
                color: white;
                border-radius: 4px;
                width: 100%;
                height: 0.8rem;
                border: none;
                font-size: 0.28rem;
            }
        }
    }
</style>